home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / language / harvest.cpt / Harvest C / CErrorLog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-16  |  9.8 KB  |  375 lines

  1. /*
  2.     Harvest C
  3.     Copyright 1992 Eric W. Sink.  All rights reserved.
  4.     
  5.     This file is part of Harvest C.
  6.     
  7.     Harvest C is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU Generic Public License as published by
  9.     the Free Software Foundation; either version 2, or (at your option)
  10.     any later version.
  11.     
  12.     Harvest C is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.     
  17.     You should have received a copy of the GNU General Public License
  18.     along with Harvest C; see the file COPYING.  If not, write to
  19.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.     
  21.     Harvest C is not in any way a product of the Free Software Foundation.
  22.     Harvest C is not GNU software.
  23.     Harvest C is not public domain.
  24.  
  25.     This file may have other copyrights which are applicable as well.
  26.  
  27. */
  28.  
  29. /******************************************************************************
  30.  CErrorLog.c
  31.  
  32.         
  33.     SUPERCLASS = CDLOGDirector
  34.     
  35.     Copyright ⌐ 1991 Symantec Corporation. All rights reserved.
  36.     
  37.  
  38.  ******************************************************************************/
  39.  
  40. #include "CErrorLog.h"
  41. #include "CStringTable.h"
  42. #include "CStringArray.h"
  43. #include "CScrollPane.h"
  44. #include "CDialogText.h"
  45. #include "CDialog.h"
  46. #include "CPaneBorder.h"
  47. #include "CApplication.h"
  48. #include "CDecorator.h"
  49. #include "CHarvestApp.h"
  50. #include "CHarvestDoc.h"
  51. #include "CDataFile.h"
  52. #include "CSourceFile.h"
  53. #include "Commands.h"
  54. #include "HarvestCommands.h"
  55. #include "AppleEvents.h"
  56. #include "Aliases.h"
  57. #include "stdarg.h"
  58. #include "tclAE.h"
  59.  
  60. #define    kDemoDlgID            1030
  61. #define openFileTCLID        5000
  62.  
  63. enum        /* window item numbers    */
  64. {
  65.     kListScrollPaneItem = 1,
  66.     kEditItem
  67. };
  68.  
  69. extern CHarvestApp    *gApplication;
  70. extern CHarvestDoc    *gProject;
  71. extern tSystem gSystem;
  72. extern CSourceFile *gCurSourceFile;
  73. extern CErrorLog *gErrs;
  74. extern    CDecorator    *gDecorator;    /* Window dressing object    */
  75.  
  76. extern Boolean FindAProcess(OSType signature,ProcessSerialNumber *process,
  77.                         ProcessInfoRec *InfoRec,
  78.                         FSSpecPtr aFSSpecPtr);
  79. char *GetPathName(char *s,char *name,short vRefNum,long dirID);
  80.  
  81. /******************************************************************************
  82.  IErrorLog
  83. ******************************************************************************/
  84.  
  85. #define maxStringLen 255
  86.  
  87. void CErrorLog::IErrorLog( void)
  88. {
  89.     CScrollPane    *scrollPane;
  90.     CPaneBorder *listBorder;
  91.     Rect    margin;
  92.     Cell    aCell;
  93.     
  94.     ErrorCount = 0;
  95.  
  96.     if (gProject) {
  97.         CDLOGDirector::IDLOGDirector( kDemoDlgID, gProject);
  98.     }
  99.     else {
  100.         CDLOGDirector::IDLOGDirector( kDemoDlgID, gApplication);
  101.     }
  102.     
  103.     itsEditItem = (CDialogText*) itsWindow->FindViewByID( kEditItem);
  104.     itsEditItem->SetFontNumber(geneva);
  105.     
  106.     scrollPane = (CScrollPane*) itsWindow->FindViewByID( kListScrollPaneItem);
  107.     
  108.     if (scrollPane)
  109.     {                
  110.         itsStringTable = new( CStringTable);
  111.         itsStringTable->IStringTable( scrollPane, itsWindow, 0, 0, 0, 0,
  112.             sizELASTIC, sizELASTIC);
  113.         itsStringTable->FitToEnclosure( TRUE, TRUE);
  114.         itsStringTable->SetDrawActiveBorder( TRUE);
  115.         itsStringTable->SetDblClickCmd(cmdOpenErrorLine);
  116.         
  117.         itsStringTable->SetID( 10);
  118.  
  119.         listBorder = new( CPaneBorder);
  120.         listBorder->IPaneBorder( kBorderFrame);
  121.         itsStringTable->SetBorder( listBorder);
  122.                 
  123.         itsStringTable->SetSelectionFlags( selOnlyOne);
  124.         
  125.         scrollPane->InstallPanorama( itsStringTable);
  126.         
  127.         itsStrings = new( CStringArray);
  128.         itsStrings->IStringArray(maxStringLen);
  129.         itsStringTable->SetArray( itsStrings, FALSE);
  130.         
  131.         SetCell( aCell, 0, 0);
  132.         itsStringTable->SelectCell( aCell, FALSE, FALSE);
  133.     }
  134.     
  135.     SetupItems();
  136.     gDecorator->StaggerWindow(itsWindow);
  137. }    /* CErrorLog::IErrorLog */
  138.  
  139. void CErrorLog::Hprintf(char *s, ...)
  140. {
  141.     va_list ap;
  142.     char *m;
  143.     va_start(ap,s);
  144.     m = (char *) icemalloc(maxStringLen+1);
  145.     vsprintf(m,s,ap);
  146.     va_end(ap);
  147.     c2pstr(m);
  148.     ErrorCount++;
  149.     itsStrings->InsertAtIndex((Ptr) m,ErrorCount);
  150. }
  151.  
  152. /******************************************************************************
  153.  DoCommand
  154. ******************************************************************************/
  155.  
  156. void CErrorLog::DoCommand( long aCmd)
  157. {
  158.     Cell    selectedCell;
  159.     Str255    string;
  160.     Boolean haveSelection;
  161.     
  162.     SetCell( selectedCell, 0, 0);
  163.     haveSelection = itsStringTable->GetSelect( TRUE, &selectedCell);
  164.     
  165.     switch (aCmd)
  166.     {
  167.         case cmdClose:
  168.             gErrs = NULL;
  169.             inherited::DoCommand(aCmd);
  170.             break;
  171.         case cmdOpenErrorLine:
  172.             /* Now we send an open message to Alpha */
  173.             gApplication->InspectSystem();
  174.             if (gSystem.hasAppleEvents && gCurSourceFile)
  175.             {
  176.                 AERecord ae;
  177.                 AEDescList aeList;
  178.                 AEDesc docDesc;
  179.                 AEAddressDesc alfa;
  180.                 OSType theSig = 'ALFA';
  181.                 OSErr err;
  182.                 FSSpec theSpec;
  183.                 char theScript[512];
  184.                 char theName[64];
  185.                 char justName[64];
  186.                 short itsVol;
  187.                 long itsDir;
  188.                 long theLine;
  189.                 int ndx;
  190.                 char path[512];
  191.                 Cell aCell = {0,0};
  192.                 Boolean thereIsASelection = false;
  193.                 StringHandle    openScript;
  194.  
  195.                 if (itsStringTable->GetSelect(false,&aCell)) {
  196.                     thereIsASelection = true;
  197.                 }
  198.                 else if (itsStringTable->GetSelect(true,&aCell)) {
  199.                     thereIsASelection = true;
  200.                 }
  201.                 itsStringTable->GetCellText(aCell,63,(StringPtr) theName);
  202.                 p2cstr(theName);
  203.                 if (theName[0] == '<') {
  204.                     /* Error appears in System Header */
  205.                     ndx = 1;
  206.                     while (theName[ndx] != '>') {
  207.                         justName[ndx-1] = theName[ndx];
  208.                         ndx++;
  209.                     }
  210.                     justName[ndx] = 0;
  211.                     itsVol = gApplication->StdIncludeVol;
  212.                     itsDir = gApplication->StdIncludeDir;
  213.                 }
  214.                 else if (theName[0] == '\"') {
  215.                     /* Error appears in user header or file */
  216.                     ndx = 1;
  217.                     while (theName[ndx] != '\"') {
  218.                         justName[ndx-1] = theName[ndx];
  219.                         ndx++;
  220.                     }
  221.                     justName[ndx] = 0;
  222.                     itsVol = gProject->itsFile->volNum;
  223.                     itsDir = gProject->itsFile->dirID;
  224.                 }
  225.                 else {
  226.                     justName[0] = 0;
  227.                 }
  228. #define USE_TCL
  229. #ifdef USE_TCL
  230.                 if (justName[0] && gSystem.hasAppleEvents) {
  231.                     GetPathName(path,justName,itsVol,itsDir);
  232.                     p2cstr(path);
  233.                     while (!isdigit(theName[ndx])) ndx++; /* skip the colon */
  234.                     theLine = atoi(theName+ndx);
  235.             
  236.                     openScript = GetString(openFileTCLID);
  237.                     FailNILRes( openScript);
  238.                     HLock(openScript);
  239.                     sprintf(theScript,(char *) (*openScript),path,theLine);
  240.                     HUnlock(openScript);
  241.                     
  242.                     err = AECreateDesc(typeApplSignature,(Ptr) &theSig,(Size) sizeof(theSig),&alfa);
  243.                     FailOSErr(err);
  244.                     err = AECreateAppleEvent(kTclClass,kAEEval,&alfa,kAutoGenerateReturnID,
  245.                         kAnyTransactionID,&ae);
  246.                     FailOSErr(err);
  247.                     err = AECreateList(NULL,0,FALSE,&aeList);
  248.                     FailOSErr(err);
  249.                     err = AECreateDesc(typeCString,(Ptr) theScript, strlen(theScript)+1,
  250.                         &docDesc);
  251.                     FailOSErr(err);
  252.                     err = AEPutDesc(&aeList,0,&docDesc);
  253.                     FailOSErr(err);
  254.                     err = AEPutParamDesc(&ae,keyDirectObject,&aeList);
  255.                     FailOSErr(err);
  256.                     err = AESend(&ae,NULL,kAENoReply,kAENormalPriority,0,NULL,NULL);
  257.                     FailOSErr(err);
  258.                     if (!err) {
  259.                         ProcessSerialNumber process;
  260.                         ProcessInfoRec InfoRec;
  261.                         FSSpec theSpec;
  262.                         if (FindAProcess('ALFA',&process,&InfoRec,&theSpec)) {
  263.                             SetFrontProcess(&process);
  264.                         }
  265.                     }
  266.                 }
  267. #else
  268.                 if (justName[0]) {
  269.                 if (gSystem.hasAppleEvents && theSig)
  270.                 {
  271.                     AliasHandle withThis;
  272.                     
  273.                     GetPathName(path,justName,itsVol,itsDir);
  274.                     FSMakeFSSpec(itsVol,
  275.                                 itsDir,
  276.                                 path,
  277.                                 &theSpec);
  278.                     err = AECreateDesc(typeApplSignature,(Ptr) &theSig,(Size) sizeof(theSig),&alfa);
  279.                     FailOSErr(err);
  280.                     err = AECreateAppleEvent(kCoreEventClass,kAEOpenDocuments,&alfa,kAutoGenerateReturnID,
  281.                         kAnyTransactionID,&ae);
  282.                     FailOSErr(err);
  283.                     err = AECreateList(NULL,0,FALSE,&aeList);
  284.                     FailOSErr(err);
  285.                     NewAlias(NULL,&theSpec,&withThis);
  286.                     HLock((Handle) withThis);
  287.                     err = AECreateDesc(typeAlias,(Ptr) *withThis, GetHandleSize((Handle) withThis),
  288.                         &docDesc);
  289.                     FailOSErr(err);
  290.                     HUnlock((Handle) withThis);
  291.                     err = AEPutDesc(&aeList,0,&docDesc);
  292.                     FailOSErr(err);
  293.                     err = AEPutParamDesc(&ae,keyDirectObject,&aeList);
  294.                     FailOSErr(err);
  295.                     err = AESend(&ae,NULL,kAENoReply,kAENormalPriority,0,NULL,NULL);
  296.                     FailOSErr(err);
  297.                     if (!err) {
  298.                         ProcessSerialNumber process;
  299.                         ProcessInfoRec InfoRec;
  300.                         FSSpec theSpec;
  301.                         if (FindAProcess(theSig,&process,&InfoRec,&theSpec)) {
  302.                             SetFrontProcess(&process);
  303.                         }
  304.                     }
  305.                 }
  306.                 }
  307. #endif
  308.                 }
  309.             break;
  310.         default: 
  311.                 inherited::DoCommand( aCmd);
  312.                 break;
  313.     }
  314.                 
  315. }    /* CErrorLog::DoCommand */
  316.  
  317. /******************************************************************************
  318.  SetupItems
  319. ******************************************************************************/
  320.  
  321. void CErrorLog::SetupItems( void)
  322. {
  323.     Cell    selectedCell;
  324.     Boolean haveSelection;
  325.     CDialog    *dialog;
  326.     Str255    str;
  327.  
  328.     /* determine if any cells are now selected    */
  329.     
  330.     SetCell( selectedCell, 0, 0);
  331.     haveSelection = itsStringTable->GetSelect( TRUE, &selectedCell);
  332.     
  333.     dialog = (CDialog*) itsWindow;
  334.     
  335.     if (haveSelection)
  336.         itsStrings->GetItem( str, selectedCell.v+1);
  337.     else
  338.         str[0] = 0;
  339.  
  340.     itsEditItem->SetTextString( str);
  341.     itsEditItem->SelectAll( kRedraw);
  342.  
  343. }    /* CErrorLog::SetupItems */
  344.  
  345. /******************************************************************************
  346.  ProviderChanged
  347. ******************************************************************************/
  348.  
  349. void CErrorLog::ProviderChanged( CCollaborator *aProvider, long reason,
  350.                                         void *info)
  351. {
  352.     Cell    selectedCell;
  353.     Boolean haveSelection;
  354.  
  355.     if ((aProvider == itsStringTable) && (reason == tableSelectionChanged))
  356.     {
  357.         SetupItems();
  358.     }
  359.     else
  360.         inherited::ProviderChanged( aProvider, reason, info);
  361.  
  362. }    /* CErrorLog::ProviderChanged */
  363.  
  364. /******************************************************************************
  365.  Dispose
  366. ******************************************************************************/
  367.  
  368. void CErrorLog::Dispose( void)
  369. {
  370.     ForgetObject( itsStrings);
  371.     ForgetObject( itsStringTable);
  372.     inherited::Dispose();
  373. }
  374.  
  375.